<%--
  Created by IntelliJ IDEA.
  User: 10944
  Date: 2021/8/12
  Time: 14:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
%>
<script src="<%=path%>/static/jquery/jquery-3.6.0.min.js"></script>
<script src="<%=path%>/static/hui/lib/layer/2.4/layer.js"></script>
<script src="<%=path%>/static/js/common.js"></script>
<link href="<%=path%>/static/modal/bootstrap-4.6.0-dist/css/bootstrap.min.css" rel="stylesheet"/>

<html>
<head>
    <title>add</title>

</head>
<body class="body">
<div class="page-container">
    <h2 class="mt-3 mb-3">添加菜品</h2>
    <hr>
    <div class="container-md">
        <div id="filePickerContainer">
            <form class="form" onsubmit="return false;">
                <div class="form-group">
                    <label>菜名</label>
                    <input type="text" id="menusName" name="menusName" value="${param.menusName}" class="form-control">
                </div>
                <div class="form-group">
                    <label>类别</label>
                    <input type="text" id="menusClass" name="menusClass" value="${param.menusClass}"
                           class="form-control">
                </div>
                <div class="form-group">
                    <label>成本</label>
                    <input type="text" id="menusCost" value="${param.menusCost}" name="menusCost" class="form-control">
                </div>
                <div class="form-group">
                    <label>售价</label>
                    <input type="text" id="menusPrice" value="${param.menusPrice}" name="menusPrice"
                           class="form-control">
                </div>
                <div class="col">
                    <div class="laydate-footer-btns right-button">
                        <button class="btn btn-success float-right btn-lg" type="button" onclick="add()">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
    <script>
        function add() {
            var menusName = $("#menusName").val();
            var menusClass = $("#menusClass").val();
            var menusCost = $("#menusCost").val();
            var menusPrice = $("#menusPrice").val();
            if ((menusName != null || menusName != "") && (menusClass != null || menusClass != "") && (menusCost != null || menusCost != "") && (menusPrice != null || menusPrice != "")) {
                $.ajax({
                    url: "add",
                    method: "post",
                    type: "text",
                    data: {
                        menusName: $("#menusName").val(),
                        menusClass: $("#menusClass").val(),
                        menusCost: $("#menusCost").val(),
                        menusPrice: $("#menusPrice").val(),
                    },
                    success: function (data) {
                        if (data == "ok") {
                            alert("添加成功了!");
                            parent.location.reload()
                            layer_close();
                        } else {
                            alert("添加失败了!");
                        }
                    }, error: function (e) {
                        alert("服务器错误!");
                    }
                })
            } else {
                alert("请输入全部信息");
            }
        }
    </script>
</body>
</html>
